package com.cat.dataStructure02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/global-and-local-inversions/description/
 * @create 2025/10/20 15:47
 * @since JDK17
 */

public class Solution29 {
    public boolean isIdealPermutation(int[] nums) {
        int n = nums.length;
        int[] min = new int[n];
        min[n - 1] = nums[n - 1];
        for (int i = n - 2; i > 0; i--) {
            min[i] = Math.min(nums[i], min[i + 1]);
        }
        for (int i = 0; i < n - 2; i++) {
            if (nums[i] > min[i + 2]) {
                return true;
            }
        }

        return true;
    }
}
